from temp import ReadExcel
import shutil
from glob import glob
import os
from temp import Graphics
from expert import Expert
class FileController:
    from_file = 0
    def __init__(self):
        self.expert = Expert()
        self.basic_folder = 'data'
        self.mode1_folder = 'mode1'
        self.mode2_folder = 'mode2'
        self.mode3_folder = 'mode3'
        self.mode1_process = 0
        self.mode2_process = 0
        self.mode3_process = 0

    def OpenFolderProject(self, folder):
        if os.path.isdir(self.basic_folder):
            shutil.rmtree(self.basic_folder)
        if os.path.isdir(self.mode1_folder):
            shutil.rmtree(self.mode1_folder)
        if os.path.isdir(self.mode2_folder):
            shutil.rmtree(self.mode2_folder)
        if os.path.isdir(self.mode3_folder):
            shutil.rmtree(self.mode3_folder)
        os.mkdir(self.basic_folder)
        shutil.copytree(folder, self.basic_folder)

    def SaveFolderProject(self):
        if self.mode1_process:
            grap = Graphics(self.GetFileNameGraphics(self.mode1_folder))
            if grap:
                match self.expert.engine_type:
                    case "L3":
                        grap.save_l3_v6_graphics(self.mode1_folder)
                    case "L4":
                        grap.save_l4_v8_graphics(self.mode1_folder)
                    case "L6":
                        grap.save_l6_v12_graphics(self.mode1_folder)
                    case "V6":
                        grap.save_l3_v6_graphics(self.mode1_folder)
                    case "V8":
                        grap.save_l4_v8_graphics(self.mode1_folder)
                    case "V12":
                        grap.save_l6_v12_graphics(self.mode1_folder)
        if self.mode2_process:
            grap = Graphics(self.GetFileNameGraphics(self.mode2_folder))
            if grap:
                match self.expert.engine_type:
                    case "L3":
                        grap.save_l3_v6_graphics(self.mode2_folder)
                    case "L4":
                        grap.save_l4_v8_graphics(self.mode2_folder)
                    case "L6":
                        grap.save_l6_v12_graphics(self.mode2_folder)
                    case "V6":
                        grap.save_l3_v6_graphics(self.mode2_folder)
                    case "V8":
                        grap.save_l4_v8_graphics(self.mode2_folder)
                    case "V12":
                        grap.save_l6_v12_graphics(self.mode2_folder)
        if self.mode3_process:
            grap = Graphics(self.GetFileNameGraphics(self.mode3_folder))
            if grap:
                match self.expert.engine_type:
                    case "L3":
                        grap.save_l3_v6_graphics(self.mode3_folder)
                    case "L4":
                        grap.save_l4_v8_graphics(self.mode3_folder)
                    case "L6":
                        grap.save_l6_v12_graphics(self.mode3_folder)
                    case "V6":
                        grap.save_l3_v6_graphics(self.mode3_folder)
                    case "V8":
                        grap.save_l4_v8_graphics(self.mode3_folder)
                    case "V12":
                        grap.save_l6_v12_graphics(self.mode3_folder)
    def GetFileNameGraphics(self, folder):
        try:
            return glob(self.basic_folder + "/" + folder + "/*.xlsx")[0]
        except:
            pass